package com.teach;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Arrays;

public class Test1 {

	public static void main(String[] args)throws Exception {
		/**
		 * in.txt
		 * ABC\nabc 65,66,67,13,10,97,98,99
		 */
		File f1 = new File("d:/upload/in.txt");
		InputStream in = new FileInputStream(f1);
		int temp = in.read();
		System.out.println(temp);
		temp = in.read();
		System.out.println(temp);
		temp = in.read();
		System.out.println(temp);
		temp = in.read();
		System.out.println(temp);
		temp = in.read();
		System.out.println(temp);
		temp = in.read();
		System.out.println(temp);
		temp = in.read();
		System.out.println(temp);
		temp = in.read();
		System.out.println(temp);
		temp = in.read();
		System.out.println(temp);
		temp = in.read();
		System.out.println(temp);
		
		System.out.println("---------------");
		
		in = new FileInputStream(f1);
		int b = 0;
		while((b=in.read()) != -1) {
			System.out.println(b);
		}
		
		System.out.println("---------------");
		in = new FileInputStream(f1);
		byte[] bs = new byte[6];//一次读取1k
		
		int len = in.read(bs);//从字节输入流中读取到bs.length到字节数组中
		System.out.println("bs:"+Arrays.toString(bs));
		System.out.println("len:"+len);
		
		len = in.read(bs);//从字节输入流中读取到bs.length到字节数组中
		System.out.println("bs:"+Arrays.toString(bs));
		System.out.println("len:"+len);
		
		len = in.read(bs);//从字节输入流中读取到bs.length到字节数组中
		System.out.println("bs:"+Arrays.toString(bs));
		System.out.println("len:"+len);
//		in.read(bs, 0, bs.length);//= in.read(bs)
		
		System.out.println("------------------");
		
		in = new FileInputStream(f1);
		bs = new byte[6];//一次读取1k -> 6
		len = 0;
		while((len=in.read(bs)) > -1) {
			System.out.println("bs:"+Arrays.toString(bs)+" 有效："+len);
		}
		
		
		
	}
}
